package com.myapp.mobilesafe.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;

import com.myapp.mobilesafe.utils.PrefUtils;

public class BootCompleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Boolean protect = PrefUtils.getBoolean("protect", false, context);
        if(!protect){
            return;
        }
       String bindedSIM = PrefUtils.getString("bind_sim",null,context);
        if(!TextUtils.isEmpty(bindedSIM)){
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String currentSIM = tm.getSimSerialNumber();
            Log.i("hahah","@@@@@@@$$$广播进入");
            if(currentSIM.equals(bindedSIM)){
                Log.i("hahah","已检查SIM安全");
            }else {
                Log.i("hahah","警告 SIM卡已变更");
                String phone = PrefUtils.getString("save_phone","",context);
                SmsManager sm = SmsManager.getDefault();
                sm.sendTextMessage(phone,null,"SIM CARD CHANGED!!",null,null);
            }
        }
    }
}
